package com.example.demo.service;

import com.example.demo.mapper.UserInfoMapper;
import com.example.demo.model.UserInfo;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Slf4j
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 根据名字查密码 并且 校验密码是否正确
     * @param name 用户名
     * @param password 密码
     * @return true ：密码正确   false：密码错误或者用户名不存在
     */
    public Boolean login(String name, String password){
        try {
            UserInfo userInfo = userInfoMapper.selectByName(name);
            if(userInfo==null||userInfo.getId()<0){
                return false;
            }
            if(name.equals(userInfo.getUserName())&&password.equals(userInfo.getPassword())){
                return true;
            }else{
                return false;
            }
        }catch (Exception e){
            log.error("mapper层返回异常{}",e);
            return false;
        }

    }
}
